import React from 'react';
import { useLocation, Navigate } from "react-router-dom";
import {store} from '@/redux/index'
// import { rootRouter } from '@/routers/index'
// import { searchRoute } from '@/utils/index'

function AuthRouter(props: { children: JSX.Element}) {
    const { pathname } = useLocation();

    // const currentRoute = searchRoute(pathname,rootRouter)
    let token = store.getState().global.token;
    if (!token && pathname !== '/login') {
        return <Navigate to="/login" replace/>;
    } else {
        return props.children;
    }
}
export  default  AuthRouter;
